using System.Collections.Generic;
using TestCases.CompareAssert.Core.Comparers.Interfaces;
using TestCases.CompareAssert.Core.Interfaces;
using TestCases.Utils.Pairs;

namespace TestCases.CompareAssert.Core
{
    public class CompareResult : ICompareResult
    {
        private readonly List<ICompareResult> _childs = new List<ICompareResult>();
        private readonly IObjectComparer _comparer;
        private readonly IComparerObject _left, _right;

        public CompareResult(
            IObjectComparer comparer,
            CompareStatus status,
            IPair<IComparerObject, IComparerObject> objects)
        {
            _comparer = comparer;
            _left = objects.Left;
            _right = objects.Right;
            Status = status;
        }

        public CompareResult(
            IObjectComparer comparer,
            CompareStatus status,
            IPair<IComparerObject, IComparerObject> objects,
            ICompareResult childResult) : 
            this(comparer, status, objects)
        {
            _childs.Add(childResult);
        }

        public CompareResult(
            IObjectComparer comparer,
            CompareStatus status,
            IPair<IComparerObject, IComparerObject> objects,
            IEnumerable<ICompareResult> childResults) : 
            this(comparer, status, objects)
        {
            _childs.AddRange(childResults);
        }
        
        public string Message { get; set; }
        public CompareStatus Status { get; set; }

        public IObjectComparer Comparer
        {
            get { return _comparer; }
        }

        public IComparerObject Left
        {
            get { return _left; }
        }

        public IComparerObject Right
        {
            get { return _right; }
        }

        public IList<ICompareResult> ChildResults
        {
            get { return _childs.AsReadOnly(); }
        }
    }
}